package com.example.core.po;

import com.baomidou.mybatisplus.annotation.TableField;
import com.example.core.utils.UserUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.StringUtils;

@Data
public class BaseCreatePo<T> extends BasePo {

    @ApiModelProperty(value = "创建人id")
    @TableField(value = "creator_id")
    public String creatorId;

    @ApiModelProperty(value = "创建人名称")
    @TableField(value = "creator_name")
    public String creatorName;

    @ApiModelProperty(value = "更新人id")
    @TableField(value = "modify_id")
    public String modifyId;

    @ApiModelProperty(value = "更新人名称")
    @TableField(value = "modify_name")
    public String modifyName;

    @Override
    public void recalculateFields() {
        super.recalculateFields();
        if (StringUtils.isEmpty(this.creatorId)) {
            this.creatorId = UserUtils.getUserId();
            this.creatorName = UserUtils.getUserName();
        }
        this.modifyId = UserUtils.getUserId();
        this.modifyName = UserUtils.getUserName();
    }
}
